<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta content="" name="description" />
    <meta content="webthemez" name="author" />
    <meta http-equiv="pragram" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache, must-revalidate">
    <meta http-equiv="expires" content="0">

    <title>Bootstrap Admin Template</title>
    <!-- Bootstrap Styles-->
    <link href="assets/css/bootstrap.css" rel="stylesheet" />
    <!-- FontAwesome Styles-->
    <link href="assets/css/font-awesome.css" rel="stylesheet" />
    <link href="assets/css/select2.min.css" rel="stylesheet" >
    <link href="assets/css/checkbox3.min.css" rel="stylesheet" >
    <!-- Custom Styles-->
    <link href="assets/css/custom-styles.css" rel="stylesheet" />
    <!-- Google Fonts-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
</head>
<body>
<div id="page-wrapper">

    <div class="header">
        <h1 class="page-header">
            课题维护
        </h1>

    </div>


    <div id="page-inner">

        <div class="row">
            <div class="col-md-12">
                <!-- Advanced Tables -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        选题列表
                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">
                            <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline" role="grid">
                                <div class="row"><div class="col-sm-6"><div class="dataTables_length" id="dataTables-example_length">
                                    <label>指导老师：
                                        <select name="teachers" id="teachers" aria-controls="dataTables-example" class="form-control input-sm">

                                        </select>
                                    </label>
                                    <label>课题来源：
                                        <select style="width: 200px" id="topicSrc">
                                            <option value="">全部</option>
                                            <option value="A">结合教师科研</option>
                                            <option value="B">结合生产实际</option>
                                            <option value="C">结合实验</option>
                                            <option value="D">结合实际背景的专题研究</option>
                                            <option value="E">无实际背景的专题研究</option>
                                        </select>
                                    </label>
                                    <label>课题类别：
                                        <select style="width: 200px" id="topicType">
                                            <option value="">全部</option>
                                            <option value="A">学术论文</option>
                                            <option value="B">调查报告</option>
                                            <option value="C">工程设计</option>
                                            <option value="D">实验</option>
                                            <option value="E">理论计算</option>
                                        </select>
                                    </label>
                                    <label>课题名称:<input type="search" id="topicName" class="form-control input-sm" aria-controls="dataTables-example"></label>
                                </div></div><div class="col-sm-6"><div id="dataTables-example_filter" class="dataTables_filter">

                                    <label>
                                        <input type="button" class="btn btn-default" onclick="show('0')" value="查询">
                                    </label>
                                </div></div></div><table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables" aria-describedby="dataTables-example_info">



                                <thead>
                                <tr role="row">
                                    <th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column ascending" style="width: 79.6667px;">课题名称</th>
                                    <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 121.667px;">导师名</th>
                                    <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending" style="width: 112.667px;">课题类别</th>
                                    <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending" style="width: 112.667px;">课题来源</th>
                                    <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Engine version: activate to sort column ascending" style="width: 65.6667px;">已选人数</th>
                                    <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 43.6667px;">维护</th>
                                </tr>
                                </thead>
                                <tbody id="data">


                                </tbody>
                            </table>
                                <div class="row">
                                    <div class="col-sm-6">
                                        <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                                            <div id="pageGro" >
                                                <div id="pagelist">
                                                    <ul class="pagination">

                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <!--End Advanced Tables -->
                    </div>
                </div>

            </div>
        </div>

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                        <h4 class="modal-title" id="myModalLabel">维护</h4>
                    </div>
                    <div class="modal-body">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                未选题学生
                            </div>
                            <!-- /.panel-heading -->
                            <div class="panel-body">
                                <div class="table-responsive table-bordered">
                                    <table class="table">
                                        <thead>
                                        <tr>
                                            <th></th>
                                            <th>学号</th>
                                            <th>姓名</th>
                                        </tr>
                                        </thead>
                                        <tbody id="studentdata">
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
                        <button type="button" id="btn_submit" class="btn btn-primary" data-dismiss="modal" onclick="apply()"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>申请</button>
                        <!--<button type="button" id="btn_submit" class="btn btn-primary" data-dismiss="modal"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>撤销申请</button>-->
                    </div>
                </div>
            </div>
        </div>
        <!--<script type="text/javascript">-->
        <!--function showdialog(){-->
        <!--$('#myModal').modal();-->
        <!--}-->
        <!--</script>-->
        <!-- /. WRAPPER  -->
        <!-- JS Scripts-->
        <!-- jQuery Js -->
        <script src="assets/js/jquery-1.10.2.js"></script>
        <!-- Bootstrap Js -->
        <script src="assets/js/bootstrap.min.js"></script>
        <!-- Metis Menu Js -->
        <script src="assets/js/jquery.metisMenu.js"></script>
        <!-- Custom Js -->

        <!--ajax-->
        <script src="assets/js/jQuery-2.1.4.min.js"></script>
        <script src="assets/js/util.js"></script>
        <script src="assets/js/pageGroup.js"></script>
        <script>
            var pageCount=0;
            var pageSize=8;
            var pageNum=0;
            var re=getResponse('/user/findTeacher');
            var tmp = '<option value="" selected="selected">全部</option>';
            for (var i = 0; i < re.responseJSON.length; i++) {
                tmp += '<option value='+re.responseJSON[i].id+'>'
                    + re.responseJSON[i].realname + '</option>';
            }
            document.getElementById("teachers").innerHTML = tmp;
            show(pageNum);
            genPageList(pageCount,pageSize);
            function show(pageNum) {
                var teachersid=document.getElementById("teachers").value;
                var topicSrc=document.getElementById("topicSrc").value;
                var topicType=document.getElementById("topicType").value;
                var topicName=document.getElementById("topicName").value;
                var tablere=getResponse('/topic/listWithKeyMeta/8/'+pageNum,JSON.stringify({"teacherId":teachersid,"topicSrc":topicSrc,"topicType":topicType,"topicName":topicName,"markedDel":false,"state":'finished'}),"application/json");
                pageCount=tablere.responseJSON.count;
                pageSize=tablere.responseJSON.size;
                var tmp="";
                for(var i=0;i<tablere.responseJSON.objs.content.length;i++){
                    if(i%2==0){
                        tmp+='<tr class="gradeA odd">';
                        tmp+='<td class="sorting_1">'+tablere.responseJSON.objs.content[i].topicName+'</td>'
                            +'<td class="center">'+tablere.responseJSON.objs.content[i].teacherName+'</td>'
                            +'<td class="center">'+showTopicType(tablere.responseJSON.objs.content[i].topicType)+'</td>'
                            +'<td class="center">'+showTopicSrc(tablere.responseJSON.objs.content[i].topicSrc)+'</td>'
                            +'<td class="center">'+tablere.responseJSON.objs.content[i].chosePerson+'/'+tablere.responseJSON.objs.content[i].limitPerson+'</td>'
                            +'<td class="center"><a href="#" class="btn btn-success" onclick="showdialog(\''+tablere.responseJSON.objs.content[i].id+'\')" data-toggle="modal" data-target="#myModal">维护</a></td>'
                            +'</tr>';
                    }
                    else{
                        tmp+='<tr class="gradeA even">';
                        tmp+='<td class="sorting_1">'+tablere.responseJSON.objs.content[i].topicName+'</td>'
                            +'<td class="center">'+tablere.responseJSON.objs.content[i].teacherName+'</td>'
                            +'<td class="center">'+showTopicType(tablere.responseJSON.objs.content[i].topicType)+'</td>'
                            +'<td class="center">'+showTopicSrc(tablere.responseJSON.objs.content[i].topicSrc)+'</td>'
                            +'<td class="center">'+tablere.responseJSON.objs.content[i].chosePerson+'/'+tablere.responseJSON.objs.content[i].limitPerson+'</td>'
                            +'<td class="center"><a href="#" class="btn btn-success" onclick="showdialog(\''+tablere.responseJSON.objs.content[i].id+'\')" data-toggle="modal" data-target="#myModal">维护</a></td>'
                            +'</tr>';
                    }
                }
                document.getElementById("data").innerHTML=tmp;
            }
            function showTopicSrc(val){
                if(val=='A')
                    return "结合教师科研";
                if(val=='B')
                    return "结合生产实际";
                if(val=='C')
                    return "结合实验";
                if(val=='D')
                    return "结合实际背景的专题研究";
                if(val=='E')
                    return "无实际背景的专题研究";
            }
            function showTopicType(val) {
                if(val=='A')
                    return "学术论文";
                if(val=='B')
                    return "调查报告";
                if(val=='C')
                    return "工程设计";
                if(val=='D')
                    return "实验";
                if(val=='E')
                    return "理论计算";
            }


        </script>
        <script>
            function showdialog(id) {
                re=getResponse('/user/findStudent');
                //studentdata
//            <tr>
//                <th></th>
//                <th>学号</th>
//                <th>姓名</th>
//                </tr>
                var tmp='';
                for(var i=0;i<re.responseJSON.length;i++){
                    if(re.responseJSON[i].topicId!=null)
                        continue;
                    tmp+='<tr>'
                        +'<th></th>'
                        +'<th>'+re.responseJSON[i].username+'</th>'
                        +'<th>'+re.responseJSON[i].realname+'</th>'
                        +'</tr>';
                }
                document.getElementById("studentdata").innerHTML=tmp;
            }

            function apply() {
                var user= JSON.parse(sessionStorage.getItem("user"));//将json转换为对象
                var id=user.id;
                var reUser=getResponse('/user/findUser/'+id);
                if (reUser.responseJSON.topicId == null||reUser.responseJSON.topicId=="") {
                    var re=getResponse('/topic/applyTopic/'+topicid+'/'+id);
                    alert("选题成功！");
                    show(0);
                }else{
                    alert("你已选题！");
                }

            }
        </script>

</body>
</html>
